package main

import "fmt"

type person struct {
	name string
	age  int
}

type people struct {
	name string
	per  person
}

func newPerson(name string) *person {

	p := person{name: name}
	p.age = 42
	return &p
}

func newPerson2(name string, age int) *person {
	p := person{
		name: name,
		age:  age,
	}
	return &p
}

func main() {

	fmt.Println(person{"Bob", 20})

	fmt.Println(person{name: "Alice", age: 30})

	fmt.Println(person{name: "Fred"}) //不填即是默认值{Fred 0}

	fmt.Println(&person{name: "Ann", age: 40}) //&{Ann 40}

	fmt.Println(newPerson("Jon")) //&{Jon 42}

	s := person{name: "Sean", age: 50}
	fmt.Println(s.name)

	sp := &s
	fmt.Println(sp.age)

	sp.age = 51
	fmt.Println(sp.age)

	//只用一次的话也可以在函数里面定义一个结构低体
	dog := struct {
		name   string
		isGood bool
	}{
		"Rex",
		true,
	}
	fmt.Println(dog)

}
